<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

class Panelcustom{

    /**
     * Call acl group id
     * @return <Object>
     */
    public function panel_core_acl_groups()
    {
        $db 	=& JFactory::getDBO();
	$user 	=& JFactory::getUser();
	$db->setQuery("SELECT lft FROM #__core_acl_aro_groups WHERE id = ".$user->gid);
	$rs 	= $db->loadObject();
        return $rs->lft;
    }

    /**
     * List menu where is published
     * @return <ObjectList>
     */
    public function panel_menu()
    {
        $db 	=& JFactory::getDBO();
        $db->setQuery("SELECT * FROM #__menu WHERE menutype LIKE 'control-panel' AND published > 0 ORDER BY ordering ASC ");
	$rs = $db->loadObjectList();
        return $rs;
    }

    /**
     * Call intranet_users form Saas
     * @return <Object>
     */
    public function panel_users_config()
    {
        $conf = new JConfig;
        @mysql_connect($conf->host, $conf->user, $conf->password);
        @mysql_select_db('saas');

        $sql = "SELECT intranet_users"
              ." FROM db_register_demo"
              ." WHERE company_name = '".$conf->company_path."'"
               ;
        $res = mysql_query($sql);
        $obj = mysql_fetch_object($res);
        return $obj;
    }

    /**
     * Count all user right now where isn't Super administrator
     * @return <object>
     */
    public function panel_users(){
        $db 	=& JFactory::getDBO();
        $db->setQuery("SELECT id FROM #__users WHERE gid<25");
	$users = $db->loadObjectList();
        return count($users);
    }
}